package com.example.demo.controller;

import com.example.demo.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@Controller
public class SongController {
    @Autowired
    SongService songService ;
    //在线搜索
    @RequestMapping(value = "/song/searchSong",method = RequestMethod.POST)
    public Object searchSong(HttpServletRequest request){
        String key = request.getParameter("key").trim();
        String pn = ""+request.getParameter("pn").trim();//页数
        String rn = ""+request.getParameter("rn").trim();//每页记录数
        Map<String,Object> songBeans = songService.searchSongs(key,pn,rn);
        return songBeans;
    }

    //获取歌曲播放地址
    @RequestMapping(value = "/song/getSongPath",method = RequestMethod.POST)
    public Object getSongPath(HttpServletRequest request){
        String rid = request.getParameter("rid");
        String url = songService.getSongPath(rid);
        System.out.println("歌曲被查询,rid:"+rid+"，url"+url);
        return  url;
    }

}
